<?php

namespace Auth\Model;

use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class User implements InputFilterAwareInterface
{
    public $id;
    public $username;
    public $password;
    public $cmt;
	public $email;
	public $hoten;
	public $new_password;
	

    protected $inputFilter;

    /**
     * Used by ResultSet to pass each database row to the entity
     */
    public function exchangeArray($data)
    {
        $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->username = (isset($data['username'])) ? $data['username'] : null;
        $this->password  = (isset($data['password'])) ? $data['password'] : null;
        $this->cmt  = (isset($data['cmt'])) ? $data['cmt'] : null;
		$this->email  = (isset($data['email'])) ? $data['email'] : null;
		$this->hoten  = (isset($data['hoten'])) ? $data['hoten'] : null;
		$this->new_password  = (isset($data['new_password'])) ? $data['new_password'] : null;
		
    }

    public function getArrayCopy()
    {
        return get_object_vars($this);
    }

    public function setInputFilter(InputFilterInterface $inputFilter)
    {
        throw new \Exception("Not used");
    }

    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();

            $factory = new InputFactory();

            $inputFilter->add($factory->createInput(array(
                'name'     => 'id',
                'required' => true,
                'filters'  => array(
                    array('name' => 'Int'),
                ),
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'username',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min'      => 2,
                            'max'      => 10,
							'messages' => array(
                                'stringLengthTooShort' => 'Vui lòng nhập vào từ 2-10 kí tự!', 
                                'stringLengthTooLong' => 'Vui lòng nhập vào từ 2-10 kí tự!' 
                            ),
                        ),
                    ),
                ),
            )));
			
            
            $inputFilter->add($factory->createInput(array(
                'name'     => 'cmt',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min'      => 9,
                            'max'      => 9,
							'messages' => array(
                                'stringLengthTooShort' => 'Số CMT phải có 9 kí tự!', 
                                'stringLengthTooLong' => 'Số CMT phải có 9 kí tự!' 
                            ),
                        ),
                    ),
                ),
            )));
			
			$inputFilter->add($factory->createInput(array(
                'name'     => 'email',
                'validators' => array(
                    array(
                        'name'    => 'EmailAddress'
                    ),
                ),
            )));
			
			

            $this->inputFilter = $inputFilter;        
        }

        return $this->inputFilter;
    }
}
